let commonFunction = {}
const Base64 = require ('js-base64').Base64;
 /**
 * Function    : loadSaveCompUKeys
 * Description : UKey加载保存分量UKey
 * Input       : none
 * Return      : none
 */
commonFunction.loadSaveCompUKeys = function (self) {
    let _this = self;
    _this.$axios.get (_this.$uurl + '/keyscomm/loadSaveCompUKeys').then (response => {
        response = response.data;
        _this.dmkNumList = response
        if(_this.dmkNumList.length ===0){
            _this.selectUkey.deviceId = undefined
            _this.selectUkey.label = ''
        }
    }).catch(e=>{
        _this.dmkNumList = []
        _this.selectUkey.deviceId = undefined
        _this.selectUkey.label = ''
        _this.spinning = false
        _this.msg = "请插入UKey"
    })
}

commonFunction.validePassword = function (self,value,type){
    let _this = self;
    _this[type] = ''
    if (!value || value.trim ().length === 0) {
        _this[type] = '安全UKey登录密码不能为空'
    } else if (value.trim ().length < 6 || value.trim ().length > 16) {
        _this[type] = '安全UKey登录密码不能为空'
    }
}
commonFunction.verifyPinCode = function (self){
    let _this = self;
    if(_this.selectUkey.pinCode === ''){
        _this.msg = '安全UKey登录密码不能为空'
        return
    }
    if(_this.msg !== ''){
        return
    }
    let params ={
        deviceId:_this.selectUkey.deviceId,
        pinCode:Base64.encode(_this.selectUkey.pinCode),
    }
    _this.$axios.post (_this.$uurl + '/keyscomm/verifyPinCode',params).then (response => {
        response = response.data;
        if(response.code === 0){

        }else{
            _this.$message.error (response.message)
        }
    }).catch(e=>{
        _this.spinning = false
        _this.$message.warning ("请插入UKey")
    })
}
export default commonFunction
